package com.huazi.commonutils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;


/**
 * @author shkstart
 * @create 2021-03-12 14:49
 */
@Data
@Accessors(chain = true)//支持链式写法
public class CommentResult {
    @ApiModelProperty("是否成功")
    private Boolean success;
    @ApiModelProperty("返回码")
    private Integer code;
    @ApiModelProperty("返回消息")
    private String msg;
    @ApiModelProperty("返回数据")
    private  Map<String,Object> data;
    private CommentResult(){};
    private static CommentResult commentResult=new CommentResult();
    public static CommentResult getOK(){
        setInfo(true,ResultCode.SUCCESS,"成功！");
        return commentResult;
    }
    public static CommentResult getError(){
        setInfo(false,ResultCode.ERROR,"失败！");
        return commentResult;
    }
    private static void setInfo(Boolean flag,Integer code,String msg){
        commentResult.setSuccess(flag).setCode(code).setMsg(msg).setData(new HashMap<>());
    }
    public CommentResult data(String key , Object value){
        commentResult.data.put(key,value);
        return commentResult;
    }
}
